#define _CRT_SECURE_NO_WARNINGS  1
#include <stdio.h>

int is_leap_year(int i)
{
	if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0))
		return 29;
	else
		return 28;
}

int main() {
	int j = 0;
	int p = 0;
	int day = 0;
	while (scanf("%d %d", &j, &p) != EOF)
	{ 
		if ((p % 2 == 1 && p != 2 && p <= 7) || (p % 2 == 0 && p >= 8 && p != 2))
		{
			day = 31;
			printf("%d\n", day);
		}
		if ((p % 2 == 0 && p <= 7 && p != 2) || (p % 2 == 1 && p >= 8 && p != 2))
		{
			day = 30;
			printf("%d\n", day);
		}
		if (is_leap_year(j) && (p == 2))
		{
			printf("%d\n", is_leap_year(j));
		}
	}
	return 0;
}